package com.zhangxiaofanfan.hotcode.second;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 *
 * @date 2024-07-13 03:14:13
 * @author zhangxiaofanfan
 */
public class HotCode082 {
    public static void main(String[] args) {
        HotCode082 hotCode = new HotCode082();
        hotCode.generate(5).forEach(System.out::println);
    }

    public List<List<Integer>> generate(int numRows) {
        List<List<Integer>> result = new ArrayList<>();
        result.add(new ArrayList<>(List.of(1)));
        if (numRows == 1) {
            return result;
        }
        result.add(new ArrayList<>(List.of(1, 1)));
        if (numRows == 2) {
            return result;
        }
        for (int i = 2; i < numRows; i++) {
            List<Integer> update = result.getLast();
            List<Integer> cur = new ArrayList<>();
            cur.add(1);
            for (int j = 0; j < update.size() - 1; j++) {
                cur.add(update.get(j) + update.get(j + 1));
            }
            cur.add(1);
            result.add(cur);
        }
        return result;
    }
}
